package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.LRecharge;
import com.ruoyi.system.service.ILRechargeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 充值订单Controller
 *
 * @author zyb
 * @date 2022-01-02
 */
@RestController
@RequestMapping("/system/recharge")
public class LRechargeController extends BaseController {
    @Autowired
    private ILRechargeService lRechargeService;

    /**
     * 查询充值订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:recharge:list')")
    @GetMapping("/list")
    public TableDataInfo list(LRecharge lRecharge) {
        startPage();
        List<LRecharge> list = lRechargeService.selectLRechargeList(lRecharge);
        return getDataTable(list);
    }

    /**
     * 导出充值订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:recharge:export')")
    @Log(title = "充值订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LRecharge lRecharge) {
        List<LRecharge> list = lRechargeService.selectLRechargeList(lRecharge);
        ExcelUtil<LRecharge> util = new ExcelUtil<LRecharge>(LRecharge.class);
        util.exportExcel(response, list, "充值订单数据");
    }

    /**
     * 获取充值订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:recharge:query')")
    @GetMapping(value = "/{rechargeid}")
    public AjaxResult getInfo(@PathVariable("rechargeid") Long rechargeid) {
        return AjaxResult.success(lRechargeService.selectLRechargeByRechargeid(rechargeid));
    }

    /**
     * 新增充值订单
     */
    @PreAuthorize("@ss.hasPermi('system:recharge:add')")
    @Log(title = "充值订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LRecharge lRecharge) {
        return toAjax(lRechargeService.insertLRecharge(lRecharge));
    }

    /**
     * 修改充值订单
     */
    @PreAuthorize("@ss.hasPermi('system:recharge:edit')")
    @Log(title = "充值订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LRecharge lRecharge) {
        return toAjax(lRechargeService.updateLRecharge(lRecharge));
    }

    /**
     * 删除充值订单
     */
    @PreAuthorize("@ss.hasPermi('system:recharge:remove')")
    @Log(title = "充值订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{rechargeids}")
    public AjaxResult remove(@PathVariable Long[] rechargeids) {
        return toAjax(lRechargeService.deleteLRechargeByRechargeids(rechargeids));
    }

    @GetMapping(value = "/billcode")
    public AjaxResult getBillCode() {
        return AjaxResult.success(lRechargeService.getBillCode());
    }
}
